var wlist = {'lg':true, 'm':true, 'fm':true, 'u':true};
var hidden;
function getAllNeedHiddenElements()
{
  var elements = [];
  var tagNames = ['div','p','span'];
  for( var i = 0; i < tagNames.length; i++ )
  {
    var tagElements = document.getElementsByTagName(tagNames[i]);
    for( var j = 0; j < tagElements.length; j++ )
    { 
      if( !( tagElements[j].id in wlist ) && tagElements[j].id.indexOf('sd_') != 0 )
      {
        elements.push( tagElements[j] ) 
      }
    }
  }
  return elements;
}

function hiddenAllElement()
{
  function hiddenElement( element )
  {
    element.style.visibility='hidden';
  }
  var elements = getAllNeedHiddenElements();
  for( var i = 0; i < elements.length; i++ )
  {
    hiddenElement( elements[i] );
  }
  hidden = true;
}

function showAllElement()
{
  if( !hidden ) return;
  hidden = false;
  var op = 0.0;
  function showElement( element )
  {
    element.style.visibility='';
    element.style.opacity=op;
  }
  var elements = getAllNeedHiddenElements();
  var intervalProcess = setInterval( function()
  {
    if( op > 1 )
    {
      clearInterval( intervalProcess );
    }  
    for( var i = 0; i < elements.length; i++ )
    {
      showElement( elements[i] );
    }
    op += 0.1;
  }, 100 );
}
window.onload=function()
{
  var logo = document.getElementsByTagName('img')[0];
  var deg = 0;
  logo.onmouseover = function()
  {
    var intervalProcess = setInterval( function()
    {
      if( deg > 360 )
      {
        deg = 0;
        clearInterval( intervalProcess );
      }
      logo.style['-webkit-transform'] = 'rotate('+(deg)+'deg)';
      deg += 2;
    }, 20 );
    return false;
  };
  chrome.extension.sendRequest( "queryHiddenMode", function( response )
  {
    if( response == "forever" || response == "load" )
    {
      hiddenAllElement();
      if( response == "load" )
      {
        document.body.addEventListener('mousemove', function() { showAllElement(); }, false);
        document.getElementById('kw').onblur = function() { showAllElement(); };      
      }
    }
  });
};
